package com.qdu.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.qdu.entity.Cotenancy;
import com.qdu.mapper.CotenancyMapper;
import com.qdu.service.CotenancyService;
@Service
public class CotenancyServiceImpl implements CotenancyService{
	@Autowired	
	private CotenancyMapper cotenancymapper;
	@Override
	public void addCotenancy(Cotenancy cotenancy) {
		cotenancymapper.insert(cotenancy);
		
	}

	@Override
	public void updateCotenancy(Cotenancy cotenancy) {
		  cotenancymapper.update(cotenancy);

		
	}

	@Override
	public void deleteCotenancy(String uid, String hid) {
		cotenancymapper.delete(uid, hid);

		
	}

	@Override
	public List<Cotenancy> getAllCotenancyByUid(String uid) {
		// TODO Auto-generated method stub
		return cotenancymapper.getAllCotenancyByUid(uid);
	}

	@Override
	public Cotenancy getOneCotenancyByUid(String uid, String hid) {
		// TODO Auto-generated method stub
		return cotenancymapper.getOneCotenancyByUid(uid, hid);
	}



	
	@Override
	public List<Cotenancy> getCorrectHaddress(String string) {
		List<Cotenancy> newlist=new ArrayList<Cotenancy>();
		
		// TODO Auto-generated method stub
	   List<Cotenancy> list=cotenancymapper.getAllCotenancy();
		for(Cotenancy x:list)
		{
			if(x.getHaddress().contains(string))
			{
				
				newlist.add(x);
			}
		}
		return newlist;
	
	}

	@Override
	public List<Cotenancy> getCorrectHcgender(String string) {
		List<Cotenancy> newlist=new ArrayList<Cotenancy>();
		List<Cotenancy> list=cotenancymapper.getAllCotenancy();
		for(Cotenancy x:list)
		{
			if(x.getHcgender().contains(string))
			{
				
				newlist.add(x);
			}
		}
		return newlist;
	
		// TODO Auto-generated method stub
	
	}

	@Override
	public List<Cotenancy> getCorrectHdes(String string) {
		// TODO Auto-generated method stub
		List<Cotenancy> newlist=new ArrayList<Cotenancy>();
		List<Cotenancy> list=cotenancymapper.getAllCotenancy();
		for(Cotenancy x:list)
		{
			if(x.getHdes().contains(string))
			{
				
				newlist.add(x);
			}
		}
		return newlist;
	}

	@Override
	public List<Cotenancy> getCorrectHtra(String string) {
		// TODO Auto-generated method stub
		List<Cotenancy> newlist=new ArrayList<Cotenancy>();
		List<Cotenancy> list=cotenancymapper.getAllCotenancy();
		for(Cotenancy x:list)
		{
			if(x.getHtra().contains(string))
			{
				
				newlist.add(x);
			}
		}
		return newlist;
	}

	@Override
	public List<Cotenancy> getCorrectHcon(String string) {
		// TODO Auto-generated method stub
		List<Cotenancy> newlist=new ArrayList<Cotenancy>();
		List<Cotenancy> list=cotenancymapper.getAllCotenancy();
		for(Cotenancy x:list)
		{
			if(x.getHcon().contains(string))
			{
				
				newlist.add(x);
			}
		}
		return newlist;
	}

	@Override
	public List<Cotenancy> getCorrectHtype(String string) {
		// TODO Auto-generated method stub
		List<Cotenancy> newlist=new ArrayList<Cotenancy>();
		List<Cotenancy> list=cotenancymapper.getAllCotenancy();
		for(Cotenancy x:list)
		{
			if(x.getHtype().contains(string))
			{
				
				newlist.add(x);
			}
		}
		return newlist;
	}

	@Override
	public List<Cotenancy> getCorrectHpic(String string) {
		// TODO Auto-generated method stub
		List<Cotenancy> newlist=new ArrayList<Cotenancy>();
		List<Cotenancy> list=cotenancymapper.getAllCotenancy();
		for(Cotenancy x:list)
		{
			if(x.getHpic().contains(string))
			{
				
				newlist.add(x);
			}
		}
		return newlist;
	}

	@Override
	public List<Cotenancy> getCorrectCprice( Integer online, Integer offline) {
		List<Cotenancy> newlist=new ArrayList<Cotenancy>();
		
			// TODO Auto-generated method stub
		   List<Cotenancy> list=cotenancymapper.getAllCotenancy();
			for(Cotenancy x:list)
			{
	
	
				if(x.getCprice()>=offline&&x.getCprice().intValue()<=online)
				{
					
					newlist.add(x);
				}
			}
			return newlist;
		

	}

	@Override
	public List<Cotenancy> getAllCotenancy() {

		return cotenancymapper.getAllCotenancy();
	}

}
